import React, { useEffect, useState } from "react";
import axios from "axios";

export default function Booklist() {
  const [booklist, setBooklist] = useState([]);

  useEffect(() => {
    //TODO: 数据请求
    axios("http://127.0.0.1:3010/api/book/all")
      .then((res) => {
        if (res.data.list) {
          setBooklist(res.data.list);
        }
      })
      .catch((e) => console.error(e));
  }, []);

  return (
    <div>
      <h3>书目列表</h3>
      <ul>
        {booklist.map((book) => (
          <li key={book}>{book}</li>
        ))}
      </ul>
    </div>
  );
}
